home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tpl60n19.zip / ARISOURC.ZIP / LONGMUL.ASM < prev    next >
Assembly Source File  |  1993-01-25  |  3KB  |  76 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 6.0        *
  5. ; *     Longint Multiplication / Squaring               *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1991-1993 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   LONGMUL
  12.  
  13.  
  14. CODE         SEGMENT BYTE PUBLIC
  15.  
  16.              ASSUME  CS:CODE
  17.  
  18. ; Publics
  19.  
  20.              PUBLIC  LongMul,LongSqr
  21.  
  22. ;-------------------------------------------------------------------------------
  23. ; LongSqr computes the square of its argument, a LONGINT value. No check is made
  24. ; to assert that the result does not overflow the LONGINT format. This routine
  25. ; exits through the LongMul routine.
  26. ;
  27. ; INPUT:     DX:AX      argument
  28. ;
  29. ; OUTPUT:    DX:AX      square of argument, if no overflow
  30. ;
  31. ; DESTROYS:  AX,DX,SI,DI,Flags
  32. ;-------------------------------------------------------------------------------
  33.  
  34. LongSqr      PROC    FAR
  35.              MOV     CX, AX            ; make multiplicand
  36.              MOV     BX, DX            ;  same as multiplicator
  37. LongSqr      ENDP
  38.  
  39.  
  40.  
  41. ;-------------------------------------------------------------------------------
  42. ; LongMul computes the product of its arguments, two LONGINT values. No check
  43. ; is made if the result overflows the LONGINT format.
  44. ;
  45. ; INPUT:     DX:AX      multiplicand
  46. ;            BX:CX      multiplicator
  47. ;
  48. ; OUTPUT:    DX:AX      product of multiplicand & multiplicator, if no overflow
  49. ;
  50. ; DESTROYS:  AX,DX,SI,DI,Flags
  51. ;-------------------------------------------------------------------------------
  52.  
  53. LongMul      PROC    FAR
  54.              MOV     DI, DX            ; save hi-word of multiplicand
  55.              OR      DI, BX            ; both numbers positive and < 65536?
  56.              JZ      $short            ; single multiplication sufficient
  57.              MOV     DI, DX            ; save hi-word of multiplicand
  58.              MOV     SI, AX            ; save lo-word of multiplicand
  59.              MUL     BX                ; multiplicator hi * multiplicand lo
  60.              XCHG    AX, DI            ; save product1 lo, get m'plicand hi
  61.              MUL     CX                ; multiplicator lo * multiplicand hi
  62.              XCHG    AX, SI            ; save procduct2 lo, get m'plicand lo
  63.              ADD     SI, DI            ; add product1 and product2 (result hi)
  64.              MUL     CX                ; multiplicator lo * multiplicand lo
  65.              ADD     DX, SI            ; add product3 hi to result hi
  66.              RET                       ; done
  67. $short:      MUL     CX                ; lo-word m'plicand * lo-word m'plicator
  68.              RET                       ; done
  69. LongMul      ENDP
  70.  
  71.              ALIGN   4
  72.  
  73. CODE         ENDS
  74.  
  75.              END
  76.